An embodiment of the invention relates generally to microprocessor (or simply, processor) systems, and more particularly, to the capability of such systems for converting a number from a first base representation to a second base representation.
In processor systems, there is frequently a need to convert a number from one base to another base representation. For example, while human users are accustomed to dealing with numbers in their decimal representation, computers typically perform their arithmetic in binary or hexadecimal representation. Thus, when a result has been computed in a processor system as a binary 1101, this will need to be converted to its corresponding “13” for display to a human user.
To efficiently convert between binary and decimal numbers across a wide range (e.g., integers 0 to 1018) in a processor system, a method has been developed that applies division and remainder operations to the original binary number sequentially. If c is a binary integer to be converted into its decimal format, then c may be represented in decimal asc=d0·10P+d1·10p−1+d2·10p−2+ . . . +dp−1·101+dp  (1)where the general form above allows for a total of p+1 digits of precision in the decimal representation. The division and remainder method computes each decimal digit recursively, that is the determination of a particular digit depends on a previously calculated adjacent digit. In particular, the following sequence is typically taken:
                                                                                          d                  p                                =                                ⁢                                  c                  ⁢                                                                          ⁢                  %                  ⁢                                                                          ⁢                  10                                                                                                                          d                                      p                    -                    1                                                  =                                ⁢                                                      c                    1                                    ⁢                                                                          ⁢                  %                  ⁢                                                                          ⁢                  10                                                                                        …                                                                                            d                  1                                =                                ⁢                                                      c                                          p                      -                      1                                                        ⁢                                                                          ⁢                  %                  ⁢                                                                          ⁢                  10                                                                                                                          d                  0                                =                                ⁢                                                      c                    p                                    ⁢                                                                          ⁢                  %                  ⁢                                                                          ⁢                  10                                                                    ⁢                                  ⁢                                                                              c                  1                                =                                ⁢                                                      (                                          c                      -                                              d                        p                                                              )                                    /                  10                                                                                                                          c                  2                                =                                ⁢                                                      (                                                                  c                        1                                            -                                              d                                                  p                          -                          1                                                                                      )                                    /                  10                                                                                                                                                                                                                  c                  p                                =                                ⁢                                                      (                                                                  c                                                  p                          -                          1                                                                    -                                              d                        1                                                              )                                    /                  10                                                                                        (        2        )            
The percentage sign in Equation (2) above refers to the remainder of the division of the two operands. First, dp is computed, by taking the remainder of c (the number to be converted, in binary format) divided by 10. Next, c1 is computed as shown, followed by dp−1 which uses c1. The sequence thus continues until d0, the last digit of the decimal representation, has been computed. This algorithm thus calculates, in sequence, for the case of an 18 digit decimal representation, d17, c1, d16, c2, . . . d1, c17, and d0.
In most modem processor systems, the arithmetic operations in Equation (2) above would actually be computed in binary format using, for example, division units that may be part of the arithmetic and logic unit (ALU) of a processor. An example of a processor instruction that converts a binary integer into a decimal integer is the FBSTP-Store BCD Integer and Pop instruction for the IA-32 Intel® Architecture (see IA-32 Intel® Architecture Software Developer's Manual, Volume 2A, page 3-217 (Order Number 253666, 2004)). Note that BCD refers to binary coded decimal, where each digit of the decimal representation is represented by a binary code.
Since the conversion between binary and decimal occurs quite frequently during operation of a processor system, faster conversion methodologies can greatly benefit the overall performance of the system.